<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <img v-mybind:src.jpg="img">
    <input type="button" value="修改图片" @click="changeImg">
  </div>

  <script src="./js/vue.js"></script>
  <script>
    let a = new Vue({
      el: "#app",
      data: {
        msg: "hello",
        img: "./imgs/1"
      },

      directives: {
        "mybind": function (el, binding) {
          if (binding.modifiers.jpg) {
            el[binding.arg] = binding.value + ".jpg";
          } else {
            el[binding.arg] = binding.value;
          }
        }
      },
      
      methods: {
        changeImg() {
          this.img = './imgs/2'
        }
      },
    })
  </script>
</body>

</html>